#include <iostream>
#include <algorithm>

using ull = unsigned long long;

auto &is = std::cin;
auto &os = std::cout;

ull n, a, b, depth;

/*
cal(a,b)
1)a==b return 0;
2)a>b && a is odd return cal(a+1,b)+1;
3)a>b && a is even return cal(a/2,b)+1;
4)a>b/2 && a<b return b-a;
5)a<b/2 && b is odd return cal(a,b/2)+1;
6)a<b/2 && b is even return cal(a,b-1)+1;
*/
ull cal(const ull a,const ull b)noexcept{
    if(a==b){
        return 0;
    }else if(a>b){
        if(a&1)return cal(a+1,b)+1;
        else return cal(a/2,b)+1;
    }else if(a>b/2){
        const auto ans = b-a;
        if(b&1)return std::min(ans,cal(a,b-1)+1);
        else return std::min(ans,cal(a,b/2)+1);
    }else if(a<=b/2){
        if(b&1)return cal(a,b-1)+1;
        else return cal(a,b/2)+1;
    }
    _Exit(1);
}

int main(){
    is>>n;
    for(ull i {0};i<n;i++){
        is>>a>>b;
        os<<cal(a,b)<<'\n';
    }
}